<html>
<head><meta charset="utf-8"><title>Generating pretty names for MIR temporaries · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Generating.20pretty.20names.20for.20MIR.20temporaries.html">Generating pretty names for MIR temporaries</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="241444864"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Generating%20pretty%20names%20for%20MIR%20temporaries/near/241444864" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thomas Del Vecchio <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Generating.20pretty.20names.20for.20MIR.20temporaries.html#241444864">(Jun 03 2021 at 20:01)</a>:</h4>
<p>We’re working on developing a new codegen backend for Rust at the MIR level. Our codegen currently does a pass over all of the LocalDecls to generate Symbols, which are then used to display program traces. At the moment, the generated temporaries are flooding our traces, making it difficult to follow. To improve this, we want to keep track of pretty names for the temporaries that suggest their significance. </p>
<p>Specifically, right now we want to find temporaries that are simple copies, moves, or derefs of other temporaries that already have meaningful names (e.g. ones that directly represent Rust variables), and generate suggestive names based off that.</p>
<p>My current approach is, as we pass over the Local, find all statements within basic blocks that assign to the Local, and check if they are a simple copy, etc. of another Local we’ve already scanned. If it is, then we set the pretty name appropriately, and otherwise, we just use the default generated name (e.g. “var_5”).</p>
<p>Two questions: 1) Is there another approach that might be more robust/simpler? 2) Given this approach, does there exist a way to directly find all statements which assign to a given Local, or do I just have to do a manual iteration over the basic blocks and their contained statements?</p>
<p>Thanks!</p>



<a name="241453683"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Generating%20pretty%20names%20for%20MIR%20temporaries/near/241453683" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Generating.20pretty.20names.20for.20MIR.20temporaries.html#241453683">(Jun 03 2021 at 21:05)</a>:</h4>
<p>Yoy could look at the <code>var_debug_info</code> field of <code>mir::Body</code>. This will help for all user defined locals, but not for temporaries.</p>



<a name="241526144"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Generating%20pretty%20names%20for%20MIR%20temporaries/near/241526144" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thomas Del Vecchio <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Generating.20pretty.20names.20for.20MIR.20temporaries.html#241526144">(Jun 04 2021 at 12:12)</a>:</h4>
<p>We currently use the <code>var_debug_info</code> to get pretty names for user defined locals, but this doesn't let us know when a temporary <code>_5</code> is just a <code>copy</code> of a user defined local <code>x</code>, in which case we want to use a name like <code>x_5</code> for the pretty name.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>